/*
 * PanelDelegate.cpp  0.4.0 / Dec 05, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "PanelDelegate.h"

// #include "com_cute4j_swing_Panel.h" // TODO: remove

// PanelDelegate :: Protected Constructor. -------------------------------------

/*!
 * \brief Constructs new PanelDelegate object.
 *
 * \param env the JNIEnv pointer
 * \param obj the Panel java object
 */
PanelDelegate::PanelDelegate(JNIEnv *env, jobject obj)
  : ContainerDelegate(env, obj, new QFrame())
{
  // empty constructor body
}

// PanelDelegate :: Native Calls. ----------------------------------------------

/*!
 * \brief Sets panel type
 *
 * \param env the JNIEnv pointer
 * \param panelType the panel type
 */
void PanelDelegate::setPanelType(JNIEnv *env, jint panelType)
{
  Q_ASSERT(env);
  SWING_REENTRANT(setPanelType, SWING_ENV_ARG, JINT_ARG(panelType))
  qFrame()->setFrameShape(QFrame::Shape(panelType));
}

/*!
 * \brief Sets border style.
 *
 * \param env the JNIEnv pointer
 * \param borderStyle the border style
 */
void PanelDelegate::setBorderStyle(JNIEnv *env, jint borderStyle)
{
  Q_ASSERT(env);
  SWING_REENTRANT(setBorderStyle, SWING_ENV_ARG, JINT_ARG(borderStyle))
  qFrame()->setFrameShadow(QFrame::Shadow(borderStyle));
}

/*!
 * \brief Sets border width.
 *
 * \param env the JNIEnv pointer
 * \param borderWidth the border width
 */
void PanelDelegate::setBorderWidth(JNIEnv *env, jint borderWidth)
{
  Q_ASSERT(env);
  SWING_REENTRANT(setBorderWidth, SWING_ENV_ARG, JINT_ARG(borderWidth))
  qFrame()->setMidLineWidth(borderWidth);
}

// PanelDelegate :: Static Native Calls. ---------------------------------------

/*!
 * \brief Returns new instance of the delegate object
 *
 * \param env the JNIEnv pointer
 * \param obj the Swing object
 * 
 * \return new instance of the delegate object
 */
jlong PanelDelegate::newInstance(JNIEnv *env, jobject obj)
{
  if (JNISwingWrapper::isSwingThread(env)) {
    return reinterpret_cast<jlong>(new PanelDelegate(env, obj));
  }
  return SwingUtilitiesDelegate::invokeLongAndWait(env, obj, createMID());
}
